﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Microfinance_Management
{
    public partial class Cust_search : Form
    {
        private string m_id;
        public Cust_search(string id)
        {
            m_id = id;
            InitializeComponent();
        }

        unsafe private void Cust_search_Load(object sender, EventArgs e)
        {
           // StringBuilder cust_id = new StringBuilder(30);
            StringBuilder name = new StringBuilder(30);
            StringBuilder state = new StringBuilder(50);
            StringBuilder city = new StringBuilder(50);
            StringBuilder address = new StringBuilder(50);
            StringBuilder tel = new StringBuilder(50);
            StringBuilder mail = new StringBuilder(255);
            Select_dll.GetCustInfo(m_id, name, state, city,
                address, tel, mail);
            textBox1.Text = name.ToString();
            textBox9.Text = state.ToString();
            textBox7.Text = city.ToString();
            textBox5.Text = address.ToString();
            textBox2.Text = m_id.ToString();
            textBox8.Text = tel.ToString();
            textBox14.Text = mail.ToString();


            int loan_num;
            int amount;
            listView1.View = View.Details;
            StringBuilder start_date = new StringBuilder(30);
            StringBuilder due_date = new StringBuilder(30);
            StringBuilder check_date = new StringBuilder(30);
            int i = 0;
            string cust_id = m_id.ToString();
            Payment_dll.startGetLoan(cust_id);
            listView1.Items.Clear();
            while (Payment_dll.GetLoan(&loan_num, start_date, due_date, check_date, &amount))
            {
                listView1.Items.Add(loan_num.ToString());
                listView1.Items[i].SubItems.Add(start_date.ToString());
                listView1.Items[i].SubItems.Add(due_date.ToString());
                listView1.Items[i].SubItems.Add(amount.ToString());
                listView1.Items[i].SubItems.Add(check_date.ToString());
                ++i;
            }
            if (i == 0)
            {
                MessageBox.Show("该客户无贷款");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MySQL.Excute("exec FristReject "+m_id);
            MessageBox.Show("核对成功");
            this.DialogResult = DialogResult.OK;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Pay_back newpay = new Pay_back(m_id);
            newpay.Show();
        }

    }
}
